<!DOCTYPE html>
<html lang="en">

    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta http-equiv="X-UA-Compatible" content="ie=edge">
        <title>注册领好礼</title>

        <link rel="stylesheet" type="text/css" href="__STATIC__/web/index/sweepcode/css/enter.css">

        <!-- 移动端适配 -->
        <script src="__STATIC__/web/index/sweepcode/js/public.js"></script>

        <script src="__STATIC__/web/index/sweepcode/js/jquery.js"></script>

    </head>

    <body>
        <div class="container">
            <div class="verify">
                <img class="bg1" src="__STATIC__/web/index/sweepcode/images/bg1.png" alt="">

                <div class="border-box">
                    <img class="border" src="__STATIC__/web/index/sweepcode/images/border.png" alt="">
                    <div class="part">
                        <img class="icon-phone" src="__STATIC__/web/index/sweepcode/images/phone.png" alt="">
                        <input type="number" id="phone" name="phone" placeholder="请输入手机号码" class="phone">
                    </div>
                    <div class="part2">
                        <img class="icon-zheng" src="__STATIC__/web/index/sweepcode/images/zheng.png" alt="">
                        <input type="number" id="code" name="code" placeholder="请输入验证码" class="verify-code">
                        <div class="getVerify" id="vcode" onClick="sendcode()">获取验证码</div>
                    </div>
                    <div class="button-box" onClick="addSchool()">
                        <img class="totake" src="__STATIC__/web/index/sweepcode/images/take.png" alt="">
                    </div>

                </div>

            </div>

            <div class="foot" hidden="true"> 
                <span>是否立即打开克克美APP？</span> 
                <div class="openapp" data-url="{:url('Index/openapp',['id'=>$id],'')}" onClick="openapp(this)">立即打开</div>
            </div>
        </div>

        <div class="success-bg" hidden="true">
            <div class="success">
                <img class="bg" src="__STATIC__/web/index/sweepcode/images/success.png" alt="">
                <div class="title">女王节{$money}元神券</div>
                <div class="line1">已发放至您的账户</div>
                <div class="line2">美容下单立减<span>{$money}</span>元</div>
                <div class="use" data-url="{:url('Index/openapp',['id'=>$id],'')}" onClick="openapp(this)">
                    <img src="__STATIC__/web/index/sweepcode/images/use.png" alt="">
                </div>
            </div>
            <div class="close" onClick="closealert()">
                <img src="__STATIC__/web/index/sweepcode/images/close.png" alt="">
            </div>
        </div>

        <div class="dialog-bg" style="display:none;">
            <div class="dialog-border">
                <div class="title">登录成功,是否打开克克美APP?</div>
                <div class="choose">
                    <div class="cancel part">取消</div>
                    <div class="confrim part">确定</div>
                </div>
            </div>
        </div>

        <script>
            var height = $(window).height()
            window.onload = function () {
                var real_height = height * 1 + 50 / 46.875
                var bg2_height = (height * 1 - 470) / 46.875
                $('.success-bg').attr('style', 'height:' + real_height + 'rem')
                $('.bg2').attr('style', 'height:' + bg2_height + 'rem')
                $('.dialog-bg').css('height', real_height + 'rem')
            }

            function closealert() {
                $(".success-bg").attr('hidden', 'true');
            }
            function openapp(obj) {
                var url = $(obj).data('url');
                var phone = document.getElementById("phone").value;
                window.location.href = url + '/phone/' + phone;
            }
            ;
            //注册
            function addSchool() {
                var phone = document.getElementById("phone").value;
                var code = document.getElementById("code").value;
                var id = "{$id}";
                var share_id = "{$share_id}";
                //var isno = $(".protocol").children("img").attr("src");
                //alert(isno);
                $.post(
                        "{:url('index/index/newregister','','')}",
                        {custom_phone: phone, code: code, store_id: id, share_id: share_id},
                        function (data) {
                            //alert(data.code);
                            if (data.code == 0) {
                                if (data.data == 1) {
                                    $(".success-bg").attr('hidden', false);
                                    $(".foot").attr('hidden', false);
                                } else {
//                                    var mymessage = confirm("登录成功，是否打开克克美APP?");
//                                    if (mymessage == true) {
//                                        var url = "{:url('Index/openapp',['id'=>$id],'')}";
//                                        window.location.href = url + '/phone/' + phone;
//                                    } else {
//
//                                    }
                                      $('.dialog-bg').removeClass('fadeOut');
                                      $('.dialog-bg').css('display', 'block');
                                      $('.dialog-border').addClass('fadeIn');

                                    $(".foot").attr('hidden', false);
                                }
                            } else {
                                alert(data.msg);
                            }
                        });
                window.alert = function (name) {
                    var iframe = document.createElement("IFRAME");
                    iframe.style.display = "none";
                    iframe.setAttribute("src", 'data:text/plain,');
                    document.documentElement.appendChild(iframe);
                    window.frames[0].window.alert(name);
                    iframe.parentNode.removeChild(iframe);
                }

            }
            //发送验证码
            function sendcode() {
                var phone = document.getElementById("phone").value;
                $.post(
                        "{:url('index/index/sendCode','','')}",
                        {custom_phone: phone},
                        function (data) {
                            if (data.code != 0) {
                                alert(data.msg);
                            } else {
                                setTime();
                                alert(data.msg);
                            }
                        });
                window.alert = function (name) {
                    var iframe = document.createElement("IFRAME");
                    iframe.style.display = "none";
                    iframe.setAttribute("src", 'data:text/plain,');
                    document.documentElement.appendChild(iframe);
                    window.frames[0].window.alert(name);
                    iframe.parentNode.removeChild(iframe);
                }
            }
            //获取手机唯一标识
            function see() {
                mui.plusReady(function () {
                    alert(JSON.stringify(h.device()));
                    console.log(JSON.stringify(h.device()));
                });

            }
            /*倒计时*/
            var countdown = 60;
            var _generate_code = $(".getVerify");

            /*执行倒计时*/
            function setTime() {
                if (countdown == 0) {
                    $("#vcode").attr('onClick', 'sendcode()');
                    _generate_code.attr("disabled", false);
                    _generate_code.text("获取验证码");
                    countdown = 60;
                    clearInterval(intervalTime) //清楚计时器
                    return
                } else {
                    $("#vcode").attr('onClick', '');
                    $(".getVerify").attr("disabled", true);
                    _generate_code.text("重新发送(" + countdown + ")");
                    countdown--;
                }


                var intervalTime = setTimeout(function () {
                    setTime()
                }, 1000);
            }

            // 搜索框失去焦点
            $('input').on('blur', function () {
                var t = setTimeout(function () {
                    $("body,html").scrollTop(0);
                }, 100)
            });


            $('.cancel').click(function () {
                $('.dialog-bg').addClass('fadeOut');
                setTimeout(function () {
                    $('.dialog-bg').css('display', 'none');
                }, 500);
            });

            $('.confrim').click(function () {
                var phone = document.getElementById("phone").value;
                var url = "{:url('Index/openapp',['id'=>$id],'')}";
                window.location.href = url + '/phone/' + phone;
            });
        </script>
    </body>

</html>